package com.example.demo.controller;

import java.util.List;
import com.example.demo.entity.Goods;
import com.example.demo.service.IGoodsService;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PassToken;
import com.example.demo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * goodsController
 * 
 * @author ruoyi
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/system/goods")
public class GoodsController
{
    @Autowired
    private IGoodsService goodsService;

    /**
     * 查询goods列表
     */
//    @PreAuthorize("@ss.hasPermi('system:goods:list')")
    @PassToken
    @GetMapping("/list")
    public ResponseResult list(Goods goods, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10")int pageSize)
    {
//        startPage();
       PageResult pageResult = goodsService.selectGoodsList(goods,pageNum,pageSize);
        return ResponseResult.createBySuccess(200,pageResult,"查询成功");
    }

    /**
     * 导出goods列表
     */
//    @PreAuthorize("@ss.hasPermi('system:goods:export')")
//    @Log(title = "goods", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Goods goods)
//    {
//        List<Goods> list = goodsService.selectGoodsList(goods);
////        ExcelUtil<Goods> util = new ExcelUtil<Goods>(Goods.class);
////        util.exportExcel(response, list, "goods数据");
//
//    }


    /**
     * 获取goods详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:goods:query')")
    @PassToken
    @GetMapping(value = "/{gid}")
    public ResponseResult getInfo(@PathVariable("gid") Long gid)
    {
       Goods goods =  goodsService.selectGoodsByGid(gid);

        return ResponseResult.createBySuccess(200,goods,"查询成功");

    }

    @PassToken
    @GetMapping("/list1")
    public ResponseResult getGoodsList(Goods goods) {
       List<Goods> list =  goodsService.selectGoodsListno(goods);
        return  ResponseResult.createBySuccess(200,list,"查询成功");
    }

    /**
     * 新增goods
     */
//    @PreAuthorize("@ss.hasPermi('system:goods:add')")
//    @Log(title = "goods", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseResult add(@RequestBody Goods goods)
    {
        int a = goodsService.insertGoods(goods);
        return ResponseResult.createBySuccess(200,a,"修改成功");
    }

    /**
     * 修改goods
     */
//    @PreAuthorize("@ss.hasPermi('system:goods:edit')")
//    @Log(title = "goods", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseResult edit(@RequestBody Goods goods)
    {
        int a = goodsService.updateGoods(goods);
        return ResponseResult.createBySuccess(200,a,"更新成功");

    }

    /**
     * 删除goods
     */
//    @PreAuthorize("@ss.hasPermi('system:goods:remove')")
//    @Log(title = "goods", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gids}")
    public ResponseResult remove(@PathVariable Long[] gids)
    {
        int a =goodsService.deleteGoodsByGids(gids);
        return ResponseResult.createBySuccess(200,a,"删除成功");

    }
}
